﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BySoft.Server.Business;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Enum;
using BySoft.Web.Utility;
using BySoft.Server.Consts;
using BySoft.Server.Common;
using System.Configuration;

namespace BySoft.Web.Site.SysManage
{
    public partial class PasswordChange : AuthBasePage
    {

        #region 属性定义
        private string UserID
        {
            get
            {
                return CurrentUser.UserID;
            }
        }
        #endregion


        #region 控件事件
        protected void Page_Load(object sender, EventArgs e)
        {
            txtOldPwd.Focus();
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            SysUserEntity oUser = SysUser.GetSysUserByID(UserID);
            if (oUser != null)
            {
                if (oUser.Password != CommonMethod.Encrypt(txtOldPwd.Text))
                {
                    UIHelper.AlertMessage(this.Page, Message.UserOldPwdError);
                    return;
                }
                if (txtNewPwd.Text == txtOldPwd.Text)
                {
                    UIHelper.AlertMessage(this.Page, Message.OldPwdCannotEqualNew);
                    return;
                }

                oUser.Password = CommonMethod.Encrypt(txtNewPwd.Text);
                oUser.IsDefaultPwd = "0";
                oUser.PasswordChangeDate = DateTime.Now;

                if (SysUser.UpdateSysUser(oUser))
                {
                    UIHelper.AlertMessageGoToParentURL(this.Page, Message.SaveSuccess, "/Login.aspx");
                }
                else
                {
                    UIHelper.AlertMessage(this.Page, Message.SaveFail);
                }
            }
            else
            {
                UIHelper.AlertMessage(this.Page, "用户不存在！");
            }
        }
        #endregion

    }
}
